home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxlibs / smix118 / mixtest.pas < prev    next >
Pascal/Delphi Source File  |  1995-05-24  |  6KB  |  186 lines

  1. {       SMIX is Copyright 1995 by Ethan Brodsky.  All rights reserved.       }
  2. program MixTest;
  3.   uses
  4.     CRT,
  5.     Detect,
  6.     SMix;
  7.   const
  8.     XMSRequired   = 190;    {XMS memory required to load the sounds (KBytes) }
  9.     SharedEMB     = true;
  10.       {TRUE:   All sounds will be stored in a shared EMB}
  11.       {FALSE:  Each sound will be stored in a separate EMB}
  12.     NumSounds = 6;
  13.   var
  14.     BaseIO: word; IRQ, DMA, DMA16: byte;
  15.     Sound: array[0..NumSounds-1] of PSound;
  16.     i: byte;
  17.     Counter: LongInt;
  18.     InKey: char;
  19.     Stop: boolean;
  20.     Num: byte;
  21.     Temp: integer;
  22.     OldExitProc: pointer;
  23.  
  24.   function HexW(W: word): string; {Word}
  25.     const
  26.       HexChars: array [0..$F] of Char = '0123456789ABCDEF';
  27.     begin
  28.       HexW :=
  29.         HexChars[(W and $F000) shr 12] +
  30.         HexChars[(W and $0F00) shr 8]  +
  31.         HexChars[(W and $00F0) shr 4]  +
  32.         HexChars[(W and $000F)];
  33.     end;
  34.  
  35.   procedure OurExitProc; far;
  36.    {If the program terminates with a runtime error before the extended memory}
  37.    {is deallocated, then the memory will still be allocated, and will be lost}
  38.    {until the next reboot.  This exit procedure is ALWAYS called upon program}
  39.    {termination and will deallocate extended memory if necessary.            }
  40.     var
  41.       i: byte;
  42.     begin
  43.       for i := 0 to NumSounds-1 do
  44.         if Sound[i] <> nil then FreeSound(Sound[i]);
  45.       if SharedEMB then ShutdownSharing;
  46.       ExitProc := OldExitProc; {Chain to next exit procedure}
  47.     end;
  48.  
  49.   procedure Init;
  50.     begin
  51.       Randomize;
  52.       writeln;
  53.       writeln('-------------------------------------------');
  54.       writeln('Sound Mixing Library v1.18 by Ethan Brodsky');
  55.       if not(GetSettings(BaseIO, IRQ, DMA, DMA16))
  56.         then
  57.           begin
  58.             writeln('Error initializing:  Invalid or non-existant BLASTER environment variable');
  59.             Halt(1); {BLASTER environment variable invalid or non-existant}
  60.           end
  61.         else
  62.           begin
  63.             if not(InitSB(BaseIO, IRQ, DMA, DMA16))
  64.               then
  65.                 begin
  66.                   writeln('Error initializing sound card');
  67.                   writeln('Incorrect base IO address, sound card not installed, or broken');
  68.                   Halt(2); {Sound card could not be initialized}
  69.                 end;
  70.             if SixteenBit
  71.               then writeln('BaseIO=', HexW(BaseIO), 'h    IRQ', IRQ, '    DMA8=', DMA, '    DMA16=', DMA16)
  72.               else writeln('BaseIO=', HexW(BaseIO), 'h        IRQ', IRQ, '        DMA8=', DMA);
  73.           end;
  74.       write('DSP version ', DSPVersion:0:2, ':  ');
  75.       if SixteenBit
  76.         then write('16-bit, ')
  77.         else write('8-bit, ');
  78.       if AutoInit
  79.         then writeln('Auto-initialized')
  80.         else writeln('Single-cycle');
  81.       if not(InitXMS)
  82.         then
  83.           begin
  84.             writeln('Error initializing extended memory');
  85.             writeln('HIMEM.SYS must be installed');
  86.             Halt(3); {XMS driver not installed}
  87.           end
  88.         else
  89.           begin
  90.             writeln('Extended memory succesfully initialized');
  91.             write('Free XMS memory:  ', GetFreeXMS, 'k  ');
  92.             if GetFreeXMS < XMSRequired
  93.               then
  94.                 begin
  95.                   writeln('Insufficient free XMS');
  96.                   writeln('You are probably running MIXTEST from the protected mode IDE');
  97.                   writeln('Run it from the command line or read the documentation');
  98.                   Halt(4); {Insufficient XMS memory}
  99.                 end
  100.               else
  101.                 begin
  102.                   writeln('Loading sounds');
  103.                   if SharedEMB then InitSharing;
  104.                   LoadSound(Sound[0], 'JET.RAW');
  105.                   LoadSound(Sound[1], 'GUN.RAW');
  106.                   LoadSound(Sound[2], 'CRASH.RAW');
  107.                   LoadSound(Sound[3], 'CANNON.RAW');
  108.                   LoadSound(Sound[4], 'LASER.RAW');
  109.                   LoadSound(Sound[5], 'GLASS.RAW');
  110.                   OldExitProc := ExitProc;
  111.                   ExitProc := @OurExitProc;
  112.                 end
  113.           end;
  114.       InitMixing;
  115.       writeln;
  116.     end;
  117.  
  118.   procedure Shutdown;
  119.     begin
  120.       ShutdownMixing;
  121.       ShutdownSB;
  122.  
  123.       for i := 0 to NumSounds-1 do
  124.         FreeSound(Sound[i]);
  125.       if SharedEMB then ShutdownSharing;
  126.       writeln;
  127.     end;
  128.  
  129.   begin
  130.     Init;
  131.  
  132.     StartSound(Sound[0], 0, true); {Start up the jet engine}
  133.  
  134.     writeln('Press:');
  135.     writeln('  1)  Machine Gun');
  136.     writeln('  2)  Crash');
  137.     writeln('  3)  Cannon');
  138.     writeln('  4)  Laser');
  139.     writeln('  5)  Breaking glass');
  140.     writeln('  Q)  Quit');
  141.  
  142.     Stop := false;
  143.     Counter := 0;
  144.  
  145.     repeat
  146.      {Display counters}
  147.       Inc(Counter);
  148.       write(Counter:8, IntCount:8, VoiceCount:4);
  149.       GotoXY(1, WhereY);
  150.  
  151.  
  152.      {Maybe start a random sound}
  153.       if Random(64000) = 0
  154.         then
  155.           begin
  156.             Num := Random(NumSounds-1)+1;
  157.             StartSound(Sound[Num], Num, false);
  158.           end;
  159.  
  160.      {Start a sound if a key is pressed}
  161.       if KeyPressed
  162.         then
  163.           begin
  164.             InKey := ReadKey;
  165.               case InKey
  166.                 of
  167.                   '0'..'9':
  168.                     begin
  169.                       Val(InKey, Num, Temp);
  170.                       if Num < NumSounds
  171.                         then
  172.                           StartSound(Sound[Num], Num, false);
  173.                     end;
  174.                   else
  175.                     Stop := true;
  176.                 end;
  177.           end;
  178.     until Stop;
  179.  
  180.     writeln;
  181.  
  182.     StopSound(1);
  183.  
  184.     Shutdown;
  185.   end.
  186.